package cn.itcast.jdbc.dao;

import java.io.InputStream;
import java.util.Properties;

public class DaoFactory {
	
	private static UserDao userDao = null;
	private static DaoFactory instance = new DaoFactory();
	
	private DaoFactory() {
		try {
			Properties prop = new Properties();
			InputStream inStream = DaoFactory.class.getClassLoader().getResourceAsStream("daoconfig.properties");
			prop.load(inStream);
			String userDaoClass = prop.getProperty("userDaoClass");
			Class<?> clazz = Class.forName(userDaoClass);
			userDao = (UserDao)clazz .newInstance();
		} catch (Exception e) {
			throw new ExceptionInInitializerError(e);
		} 
	}

	public static DaoFactory getInstance() {
		return instance;
	}
	
	public UserDao getUserDao() {
		return userDao;
	}

}
